﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Navigation;
using NhaHangKhachSan.NhaHangKhachSanServiceReference;
using System.ServiceModel;

namespace NhaHangKhachSan.DatPhong
{
    public partial class ChonPhong : Page
    {
        string ngayDen = "";
        string ngayDi = "";
        int nguoiLon = 0;
        int treEm = 0;
        int soPhong = 0;
        int soDem = 0;
        //
        int ketQua = 0;//so phong con trong
        //
        public ChonPhong(string _ngayDen, string _ngayDi, int _nguoiLon, int _treEm, int _soPhong, int _soDem)
        {
            InitializeComponent();
            ngayDen = _ngayDen;
            ngayDi = _ngayDi;
            nguoiLon = _nguoiLon;
            treEm = _treEm;
            soPhong = _soPhong;
            soDem = _soDem;
            dataGrid1.Loaded += new RoutedEventHandler(dataGrid1_Loaded);
        }

        void dataGrid1_Loaded(object sender, RoutedEventArgs e)
        {
            NhaHangKhachSanServiceClient client = new NhaHangKhachSanServiceClient();
            BasicHttpBinding bind = new BasicHttpBinding();
            EndpointAddress end = new EndpointAddress("http://localhost:4793/NhaHangKhachSanService.svc?wsdl");
            client.GetDSPhongTrongCompleted += new EventHandler<GetDSPhongTrongCompletedEventArgs>(client_GetDSPhongTrongCompleted);
            client.GetDSPhongTrongAsync(Convert.ToDateTime(ngayDen));
        }

        void client_GetDSPhongTrongCompleted(object sender, GetDSPhongTrongCompletedEventArgs e)
        {
            dataGrid1.ItemsSource = e.Result;          
            ketQua = e.Result.Count();
            tblKetQua.Text = Convert.ToString(ketQua);
            //tblKetQua.Loaded += new RoutedEventHandler(tblKetQua_Loaded);
        }

        //void tblKetQua_Loaded(object sender, RoutedEventArgs e)
        //{
        //    tblKetQua.Text = Convert.ToString(sophong);
        //}

        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            tblNgayDen.Text = ngayDen;
            tblNgayDi.Text = ngayDi;
            tblNguoiLon.Text = Convert.ToString(nguoiLon);
            tblTreEm.Text = Convert.ToString(treEm);
            tblSoPhong.Text = Convert.ToString(soPhong);
            tblSoDem.Text = Convert.ToString(soDem);
        }

        // Executes when the user navigates to this page.
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
        }

        private void btnBack_Click(object sender, RoutedEventArgs e)
        {
            App.ShowChonNgay();
        }

        private void btnNext_Click(object sender, RoutedEventArgs e)
        {

        }
    }
}
